package com.ssm.controller;


import com.ssm.service.CheckAnswerService;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "Check")
@CrossOrigin
public class CheckAnswerController {

    @Autowired
    public CheckAnswerService checkAnswerService;
    public void setCheckAnswerService(CheckAnswerService checkAnswerService) {
        this.checkAnswerService = checkAnswerService;
    }

    @RequestMapping(value = "CheckAnswer")
    @ResponseBody
    public JSON checkAnswer(@RequestParam(value = "problem") String problem, @RequestParam(value = "answer") String answer){
        int i = this.checkAnswerService.checkAnswer(problem,answer);
        Map map = new HashMap();
        if (i>0){
            map.put("checkAnswer","true");
        }
        else if (i==0){
            map.put("checkAnswer","false");
        }
        JSONObject jsonObject = JSONObject.fromObject(map);
        return jsonObject;
    }
}
